<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ydcloud.${packageName}.dao.${jName}Dao">
 <resultMap id="BaseResultMap" type="com.ydcloud.${packageName}.domain.${jName}">
    <id column="${jKey["sName"]}" jdbcType="${jKey["sType"]}" property="${jKey["jName"]}" />
    <#list paramList as param>
    <result column="${param["sName"]}" jdbcType="${param["sType"]}" property="${param["jName"]}" />
    </#list>
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${r"${"}criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${r"${"}criterion.condition} ${r"#{"}criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${r"${"}criterion.condition} ${r"#{"}criterion.value} and ${r"#{"}criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${r"${"}criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    ${r"#{"}listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${r"${"}criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${r"${"}criterion.condition} ${r"#{"}criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${r"${"}criterion.condition} ${r"#{"}criterion.value} and ${r"#{"}criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${r"${"}criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    ${r"${"}listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    ${jKey["sName"]}
     <#list paramList as param>,${param["sName"]}</#list>
  </sql>
  <select id="selectByCriteria" parameterType="com.ydcloud.${packageName}.domain.criteria.${jName}Criteria" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ${sName}
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${r"${"}orderByClause}
    </if>
    <if test="limit != null">
      <if test="offset != null">
        limit ${r"${"}offset}, ${r"${"}limit}
      </if>
      <if test="offset == null">
        limit ${r"${"}limit}
      </if>
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="${jKey["jType"]}" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ${sName}
    where 
    1=1 and ${jKey["sName"]} = ${r"#{"}${jKey["jName"]},jdbcType=${jKey["sType"]}}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ${sName}
    where ${jKey["sName"]} = ${r"#{"}${jKey["jName"]},jdbcType=${jKey["sType"]}}
  </delete>
  <delete id="deleteByCriteria" parameterType="com.ydcloud.${packageName}.domain.criteria.${jName}Criteria">
    delete from ${sName}
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.ydcloud.${packageName}.domain.${jName}">
    <selectKey keyProperty="${jKey["sName"]}" order="AFTER" resultType="${jKey["jType"]}">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ${sName} (
     <#list paramList as param>
     <#if (param_index==0)>
	  ${param["sName"]}
    <#else>
      ,${param["sName"]}
    </#if>
     </#list>)
    values (
    <#list paramList as param>
    <#if (param_index==0)>
	  ${r"#{"}${param["jName"]},jdbcType=${param["sType"]}}
    <#else>
      ,${r"#{"}${param["jName"]},jdbcType=${param["sType"]}}
    </#if></#list>)
  </insert>
   <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="${jKey["jName"]}">
    <selectKey keyProperty="${jKey["sName"]}" order="AFTER" resultType="${jKey["jType"]}">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ${sName} (<#list paramList as param>
     <#if (param_index==0)>
	  ${param["sName"]}
    <#else>
      ,${param["sName"]}
    </#if>
     </#list>)
    values
    <foreach collection="list" item="item" separator=",">
       (<#list paramList as param>
    <#if (param_index==0)>
	  ${r"#{"}item.${param["jName"]},jdbcType=${param["sType"]}}
    <#else>
      ,${r"#{"}item.${param["jName"]},jdbcType=${param["sType"]}}
    </#if></#list>)
    </foreach>
   </insert>
  <insert id="insertSelective" parameterType="com.ydcloud.${packageName}.domain.${jName}">
    <selectKey keyProperty="${jKey["sName"]}" order="AFTER" resultType="${jKey["jType"]}">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into ${sName}
    <trim prefix="(" suffix=")" suffixOverrides=",">
    <#list paramList as param>
      <if test="${param["jName"]} != null">
        ${param["sName"]},
      </if>
    </#list>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
    <#list paramList as param>
      <if test="${param["jName"]} != null">
        ${r"#{"}${param["jName"]},jdbcType=${param["sType"]}},
      </if>
    </#list>
    </trim>
  </insert>
  <select id="countByCriteria" parameterType="com.ydcloud.${packageName}.domain.criteria.${jName}Criteria" resultType="java.lang.Long">
    select count(*) from ${sName}
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByCriteriaSelective" parameterType="map">
    update ${sName}
    <set>
      <if test="record.${jKey["jName"]} != null">
        ${jKey["sName"]} = ${r"#{"}record.id,jdbcType=${jKey["sType"]}},
      </if>
      <#list paramList as param>
      <if test="record.${param["jName"]} != null">
        ${param["sName"]}=${r"#{"}record.${param["jName"]},jdbcType=${param["sType"]}},
      </if>
    </#list>
    </set>
  </update>
  <update id="updateByCriteria" parameterType="map">
    update ${sName}
    set ${jKey["sName"]} = ${r"#{"}record.id,jdbcType=${jKey["sType"]}},
    <#list paramList as param>
       ${param["sName"]}=${r"#{"}record.${param["jName"]},jdbcType=${param["sType"]}},
    </#list>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  
  <select id="countPage" resultType="int" parameterType="map">
  	SELECT COUNT(*) FROM ${sName} 
	WHERE  1=1
	<#list paramList as param>
      <if test="${param["jName"]} != null">
       and ${param["sName"]} = ${r"#{"}${param["jName"]},jdbcType=${param["sType"]}}
      </if>
    </#list>
  </select>
  
  <select id="queryPageList" parameterType="map" resultMap="BaseResultMap">
  	
	SELECT * FROM ${sName} 
	WHERE  1=1
	<#list paramList as param>
      <if test="${param["jName"]} != null">
       and ${param["sName"]} = ${r"#{"}${param["jName"]},jdbcType=${param["sType"]}}
      </if>
    </#list>
  </select>
  
  <update id="updateByPrimaryKeySelective" parameterType="com.ydcloud.${packageName}.domain.${jName}">
    update ${sName}
    <set>
      <#list paramList as param>
      <if test="${param["jName"]} != null">
        ${param["sName"]}=${r"#{"}${param["jName"]},jdbcType=${param["sType"]}},
      </if>
      </#list>
    </set>
    where ${jKey["sName"]} = ${r"#{"}${jKey["jName"]},jdbcType=${jKey["sType"]}}
  </update>
  
  <update id="updateByIdAndResource" parameterType="com.ydcloud.${packageName}.domain.${jName}">
    update ${sName}
    <set>
      <#list paramList as param>
      <if test="${param["jName"]} != null">
        ${param["sName"]}=${r"#{"}${param["jName"]},jdbcType=${param["sType"]}},
      </if>
      </#list>
    </set>
    where ${jKey["sName"]} = ${r"#{"}${jKey["jName"]},jdbcType=${jKey["sType"]}}
  </update>
  
  <update id="updateByPrimaryKey" parameterType="com.ydcloud.${packageName}.domain.${jName}">
    update ${sName}
    set
    <#list paramList as param>
        ${param["sName"]}=${r"#{"}${param["jName"]},jdbcType=${param["sType"]}},
     </#list>
   where ${jKey["sName"]} = ${r"#{"}${jKey["jName"]},jdbcType=${jKey["sType"]}}
  </update>
  
  <update id="batchUpdate" parameterType="java.util.List">
        update ${sName}
        <trim prefix="set" suffixOverrides=",">
            <#list paramList as param>
            <trim prefix="${param["sName"]} =case " suffix="end,">
                <foreach collection="list" item="item" index="index">
	             <if test="item.${param["jName"]} !=null ">
		              when ${jKey["sName"]}=${r"#{"}item.${jKey["jName"]}} then ${r"#{"}item.${param["jName"]},jdbcType=${param["sType"]}}
		         </if>
		         <if test="item.${param["jName"]} == null ">
		              when ${jKey["sName"]}=${r"#{"}item.${jKey["jName"]}} then ${sName}.${param["sName"]}
		         </if>	
                </foreach>
            </trim>
     		</#list>
        </trim>
        where ${jKey["sName"]} in
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            ${r"#{"}item.id,jdbcType=BIGINT}
        </foreach>
    </update>
</mapper>